package com.test;

import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

import java.util.Iterator;
import java.util.Map;

/**
 * 自定义的数据处理流
 *
 */
public class MyPipline implements Pipeline {

    public void process(ResultItems resultItems, Task task) {
        Map<String, Object> mapResults = resultItems.getAll();
        Iterator<Map.Entry<String, Object>> iter = mapResults.entrySet().iterator();
        Map.Entry<String, Object> entry;
        // 输出到控制台
        while (iter.hasNext()) {
            entry = iter.next();
            System.out.println("属性键值对: " + entry.getKey() + "：" + entry.getValue());
        }
        String title = (String) mapResults.get("title");
        System.out.println("Title:" + title);

    }

}
